package sketchpad.gui.component;

import com.jfoenix.controls.JFXButton;
import javafx.geometry.Insets;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import sketchpad.constant.Geometry;
import sketchpad.gui.control.DrawControl;

public class MyHBox {

    private static final String FX_BACKGROUND_COLOR = "-fx-background-color: ";
    private static final String FX_TEXT_FILL = "-fx-text-fill: ";

    private MyHBox(){}

    public static HBox constructHBox(DrawControl drawControl, Stage stage, FileExplorer fileExplorer){
        //添加按钮
        JFXButton button1 = new JFXButton("画圆");
        button1.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
            drawControl.setCurrentState(Geometry.CIRCLE);
            drawControl.setSelect(false);
        });
        JFXButton button2 = new JFXButton("画矩形");
        button2.addEventHandler(MouseEvent.MOUSE_CLICKED,event -> {
            drawControl.setCurrentState(Geometry.RECTANGLE);
            drawControl.setSelect(false);
        });
        JFXButton button3 = new JFXButton("画三角形");
        button3.addEventHandler(MouseEvent.MOUSE_CLICKED,event -> {
            drawControl.setCurrentState(Geometry.TRIANGLE);
            drawControl.setSelect(false);
        });
        JFXButton button4 = new JFXButton("画任意曲线");
        button4.addEventHandler(MouseEvent.MOUSE_CLICKED,event -> {
            drawControl.setCurrentState(Geometry.RANDOM);
            drawControl.setSelect(false);
        });
        JFXButton button5 = new JFXButton("清屏");
        button5.addEventHandler(MouseEvent.MOUSE_CLICKED,event -> {
            drawControl.clearScreen();
            drawControl.setSelect(false);
        });
        button5.setStyle(FX_BACKGROUND_COLOR+"red;"+FX_TEXT_FILL+"white");
        JFXButton button6 = new JFXButton("保存为");
        button6.addEventHandler(MouseEvent.MOUSE_CLICKED,event -> {
            fileExplorer.storeFile(stage, drawControl);
            drawControl.setSelect(false);
        });
        button6.setStyle(FX_BACKGROUND_COLOR+"grey;"+FX_TEXT_FILL+"white");
        JFXButton button7 = new JFXButton("打开文件");
        button7.addEventHandler(MouseEvent.MOUSE_CLICKED,event -> {
            fileExplorer.openFile(stage, drawControl);
            drawControl.setSelect(false);
        });
        button7.setStyle(FX_BACKGROUND_COLOR+"grey;"+FX_TEXT_FILL+"white");
        JFXButton button8 = new JFXButton("选择");
        button8.addEventHandler(MouseEvent.MOUSE_CLICKED,event -> {
            drawControl.setCurrentState(Geometry.RECTANGLE);
            drawControl.setSelect(true);
        });
        button8.setStyle(FX_BACKGROUND_COLOR+"#668899;"+FX_TEXT_FILL+"white");
        javafx.scene.layout.HBox hbox = new javafx.scene.layout.HBox();
        hbox.setPadding(new Insets(15, 12, 15, 12)); //节点到边缘的距离
        hbox.setSpacing(10); //节点之间的间距
        hbox.setStyle("-fx-background-color: #667799;"); //背景色
        hbox.setMaxHeight(50);
        hbox.setLayoutY(0);
        hbox.getChildren().addAll(button6,button7,button8,button1,button2,button3,button4,button5);

        return hbox;
    }
}
